package com.wsjc.manager.service.rpc.map.utils;

import java.util.Map;

import com.google.common.collect.Maps;
import com.wsjc.common.core.enums.MunicipalEnum;

/**
 * 构建 redis map keys
 * @author 93733
 *
 */
public class BuildCacheKeys {
	
	private static String show = "show";
	private static String country = "000000";
	private static String root = "wj:map:" ;
	
	/**
	 * 构建全国省市区 医院下的 监测数据结果缓存key
	 * @param dataType
	 * @param areaId
	 * @return
	 */
	public static Map<String, String> buildDetectionResultKeys(String dataType, String areaId){
		
		Map<String, String> mapKeys = Maps.newHashMap();
		/** 构建全国 map key **/
		StringBuffer buf = new StringBuffer();
		buf.append(root).append(dataType).append(":").append(country) ;
		mapKeys.put("countryKey", buf.toString()) ;
		
		/** 构建省级 map key **/
		String provinceId = areaId.substring(0, 2)+"0000";
		buf = new StringBuffer();
		buf.append(root).append(dataType).append(":").append(provinceId) ;
		mapKeys.put("provinceKey", buf.toString()) ;
		
		String cityId = "" ;
		MunicipalEnum municipalEnum = MunicipalEnum.getEnum("P"+provinceId); 
		if(null == municipalEnum){
			cityId = areaId.substring(0, 4)+"00";
			/** 构建市级 map key **/
			buf = new StringBuffer();
			buf.append(root).append(dataType).append(":").append(cityId) ;
			mapKeys.put("cityKey", buf.toString()) ;
		}
		
		/** 构建区级 map key **/
		buf = new StringBuffer();
		buf.append(root).append(dataType).append(":").append(areaId) ;
		mapKeys.put("areaKey", buf.toString()) ;
		
		return mapKeys;
	}
	
	
	/**
	 * 构建全国省市区医院展示缓存keys
	 * @param dataType
	 * @param areaId
	 * @return
	 */
	public static Map<String, String> buildShowKeys(String dataType, String areaId){
		
		Map<String, String> mapKeys = Maps.newHashMap();
		/** 构建全国 map key **/
		StringBuffer buf = new StringBuffer();
		buf.append(root).append(dataType).append(":").append(country).append(":").append(show);
		mapKeys.put("countryKey", buf.toString()) ;
		
		/** 构建省级 map key **/
		String provinceId = areaId.substring(0, 2)+"0000";
		buf = new StringBuffer();
		buf.append(root).append(dataType).append(":").append(provinceId).append(":").append(show);
		mapKeys.put("provinceKey", buf.toString()) ;
		
		String cityId = "" ;
		MunicipalEnum municipalEnum = MunicipalEnum.getEnum("P"+provinceId); 
		if(null == municipalEnum){
			cityId = areaId.substring(0, 4)+"00";
			/** 构建市级 map key **/
			buf = new StringBuffer();
			buf.append(root).append(dataType).append(":").append(cityId).append(":").append(show);
			mapKeys.put("cityKey", buf.toString()) ;
		}
		
		/** 构建区级 map key **/
		buf = new StringBuffer();
		buf.append(root).append(dataType).append(":").append(areaId).append(":").append(show);
		mapKeys.put("areaKey", buf.toString()) ;
		
		return mapKeys;
	}
	
	/**
	 * 构建全国省市区医院展示缓存key
	 * @param dataType
	 * @param areaId
	 * @return
	 */
	public static String buildShowKey(String dataType, String scope){
		
		/** 构建s map key **/
		StringBuffer buf = new StringBuffer();
		buf.append(root).append(dataType).append(":").append(scope).append(":").append(show) ;
		return buf.toString();
	}
	
	
	/**
	 * 构建单个scope 下key
	 * @param dataType
	 * @param scope
	 * @return
	 */
	public static String buildDetectionResultKey(String dataType, String scope) {
		
		/** 构建s map key **/
		StringBuffer buf = new StringBuffer();
		buf.append(root).append(dataType).append(":").append(scope) ;
		return buf.toString();
	}
	
	
	/**
	 * 构建医院部分信息缓存key
	 * @param hospitalId
	 * @return
	 */
	public static String buildHospitalShowDataKey(String dataType, String hospitalId){
		
		StringBuffer buf = new StringBuffer();
		buf.append(root).append(dataType).append(":").append(hospitalId);
		return buf.toString() ;
	}
	
	
	
	
	
	
	
	
	
	
	
    public static void main(String[] args) {
		
		String areaId = "140211";
		
		System.out.println(buildDetectionResultKeys("00S", areaId));
		
	}
	
	
	
	

}
